﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace OutlookTags.Controls
{
    public class AutoCompleteListSource : IListSource
    {
        List<string> _autoCompleteList = new List<string>();
        List<string> _filteredList = new List<string>();
        string _prefix = "";

        public void Add(string item)
        {
            _autoCompleteList.Add(item);
            UpdateList();
        }

        public void SetPrefix(string prefix)
        {
            _prefix = prefix.Trim().ToUpper();
            UpdateList();
        }

        public void Clear()
        {
            _autoCompleteList.Clear();
            UpdateList();
        }

        #region IEnumerable<string> Members

        public void UpdateList()
        {
            _filteredList.Clear();
            foreach (var item in _autoCompleteList)
            {
                if (item.ToUpper().StartsWith(_prefix))
                    _filteredList.Add(item);
            }
        }

        #endregion

        #region IListSource Members

        public bool ContainsListCollection
        {
            get { return true; }
        }

        public System.Collections.IList GetList()
        {
            return _filteredList;
        }

        #endregion
    }
}
